let _name = document.querySelector("._name>input");
let _iphone = document.querySelector("._iphone>input");
let _id = document.querySelector("._id>input");
let begbtn = document.querySelector(".begbtn");
let mybtn = document.querySelector(".mybtn")


begbtn.addEventListener("click", function () {
    if (_name.value && _iphone.value && _id.value) {
        ajax("http://newshopapi.0melon0.cn/api/f_user/register", {
                "name": `${_name.value}`,
                "phone": `${_iphone.value}`,
                "card": `${_id.value}`,
            }, "POST").then(res => {
                // console.log(res);
                console.log(res.result.token);
                if (res.result.token) {
                    window.location.href = "./select.html";
                }
                // console.log(_name.value);
                // console.log(_iphone.value);
                sessionStorage.setItem("_name", `${_name.value}`);
                sessionStorage.setItem("_phone", `${_iphone.value}`);
                sessionStorage.setItem("token", `${res.result.token}`);
                // sessionStorage.setItem("token")
                // console.log(sessionStorage.getItem("_phone"));

            })
            .catch(err => {
                console.log(err);
            });
    } else {
        alert("输入格式不正确")
    }
})

mybtn.addEventListener("click", function () {
    if (sessionStorage.getItem("token")) {
        window.location.href = "./information.html";
    }else{
        alert("还没成功预约！")
    }
})